<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="dragon.core.util.GlobalParameter"%>
<%@ include file="../../taglib.jsp"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>" />
<title>系统登录</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<%@ include file="/webmodules/console/css.jsp"%>
<%@ include file="/webmodules/console/js.jsp"%>
<script type="text/javascript" src="js/jquery.md5.js"></script>
<style type="text/css">
	html{
	background-color: #f1f4f9;
	}
    body{
    height:auto;
    background-color: #f1f4f9;
    text-align: center;
    }
	.login{
	margin:0 auto;
	margin-top: 188px;
	width: 715px;
	height: 363px;
	background-image: url("img/login/logo-bg.gif");
	background-repeat: no-repeat;
	}
	.logo{
	float: left;
	height: 302px;
	width: 416px;
	padding: 17px 0px 15px 14px;
	} 
	.logo img{
	width: 416px;
	height: 302px;
	} 
  	.form{
  	float: left;
  	height: 333px;
  	width: 280px;

  	}
  	.sysname{
  	width: 280px;
  	padding-top: 50px;
  	height: 30px;
  	color: #153F83;
  	font-size: 22px;
  	font-weight: bold;
  	}
  	.username,.password{
  	padding-top: 21px;
  	text-align: left;
  	padding-left: 111px;
  	}
  	.username input,.password input {
	width: 130px;
	height: 22px;
	}
	.keepstate {
	padding-top: 15px;
	height: 25px;
	line-height: 25px;
	font-size: 12px;
	color:red;
	}
	.keepstate span{
	cursor: pointer;
	}
    .goin{
    height: 40px;
    width:88px;
    margin:0 auto;
    cursor: pointer;
    margin-top: 10px;
    }
    .copyright{
    width:715px;
    height:30px;
    float:left;
    text-align: center;
    color: #A1A3A6;
    font-size: 14px;
    }
</style>
<script type="text/javascript">
	
<%if (session.getAttribute(GlobalParameter.User) != null) {%>
	location.href = "webmodules/console/index.jsp";
<%}%>
	/*是否以Cookie数据登录*/
	var loginViaCookie = false;

	var close = "${param.close}";
	if (close == "true") {
		window.opener = null;
		window.open("", "_self");
		window.close();
	};

	/*保持登录页在最顶层窗口*/
	if (location.href != parent.location.href) {
		parent.location.href = location.href;
	}

	function login() {
		var name = $("#name").val().trim();
		var pwd = $("#pwd").val().trim();
		if (name == '') {
			showMsg('', "请输入用户名！", true, 'error');
			$("#name").focus();
			return;
		}
		if (pwd == '') {
			showMsg('', "请输入密码！", true, 'error');
			$("#pwd").focus();
			return;
		}
		if (!loginViaCookie) {
			pwd = $.md5(pwd);
		}
		var keepstate = ($("#keepstate").attr("checked") == undefined ? "0" : "1");
		var nobrDisply = $("#ingimg");
		nobrDisply.css("top", ($("#ing").offset().top)-15 + "px");
		nobrDisply.css("left", ($("#ing").offset().left - 15) + "px");
		nobrDisply.css("z-index", 2);
		nobrDisply.css("display", "");
		$.post("dragon/core/auth/Login/loginViaAjax.ejw", {
			loginname : name,
			pwd : pwd
		}, function(r) {
			r = r.trim();
			if (r == "T") {
				if (keepstate == "1") {
					/*保存cookie*/
					if (!loginViaCookie) {/*避免重复保存Cookie*/
						setCookie(cookieName_username, name, 14);
						setCookie(cookieName_password, pwd, 14);
					}
				} else {
					/*删除cookie*/
					delCookie(cookieName_username);
					delCookie(cookieName_password);
				}
				location.href = "<u:webRoot/>/webmodules/console/index.jsp";
			} else {
				nobrDisply.css("display", "none");
				showMsg('', "用户名或密码错误！", true, 'error');
			}
		});
	};
	function clearCookie() {
		delCookie(cookieName_username);
		delCookie(cookieName_password);
		$("#name").val('');
		$("#pwd").val('');
		$("#keepstate").attr("checked", false);
	}
	$(document).ready(function() {
		var uname = getCookie(cookieName_username);
		if (uname != null && uname.toString() != "") {
			$("#name").val(uname);
		}
		var upass = getCookie(cookieName_password)
		if (upass != null && upass.toString() != "") {
			$("#pwd").val(upass);
		}
		if (uname != null && uname.toString() != "" && upass != null && upass.toString() != "") {
			$("#keepstate").attr("checked", true);
		}
		loginViaCookie = true;
	});
	$(document).keydown(function(event) {
		if (event.keyCode == 13) {
			/*回车键*/
			setTimeout(function() {
				login();
			}, 10);
		}
	});
</script>
</head>
<body>
	<div class="login">
		<div class="logo">
			<img src="${LoginLogo }" />
		</div>
		<div class="form">
			<div class="sysname">
				${WebSiteName}
			</div>
			<div class="username">
				<input name="username" id="name" tabindex="1" onchange="javascript:loginViaCookie=false;">
			</div>
			<div class="password">
				<input name="password" id="pwd" type="password" tabindex="2" onchange="javascript:loginViaCookie=false;">
			</div>
			<div class="keepstate">
				<input type="checkbox" name="keepstate" id="keepstate" value="1">两周内自动登录&nbsp;<span onclick="clearCookie();">清除Cookie</span>
			</div>
			<div class="goin" onclick="login();" id="ing">&nbsp;</div>
		</div>
		<div class="copyright">
			<a href="<sys:config parameter='VendorWebsite'/>" target="_blank" class="linkasnormal"><sys:config parameter="Vendor" /></a>&nbsp;版权所有
		</div>
	</div>
	<div id="ingimg" style="position: absolute; display: none; width: 150px; height: 88px;">正在登录...</div>
</body>
</html>
